<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />		
		<meta name="author" content="" />
		<meta name="last-edit" content="2023.03.08" />
		<title>浏览器存储</title>
		<style type="text/css">

			
		</style>

		<body>
      <button id="cookie">设置cookie</button>
      <button id="sessionStorage">设置sessionStorage</button>
      <button id="localStorage">设置localStorage</button>

			<script type="text/javascript">
        let username = NaN
        if (username != '' && username != null && username != undefined) {
          console.log('1username存在');
        }
        if (username) {
          console.log('2username存在');
        }

        // Cookie
        document.querySelector('#cookie').onclick = () => {
          document.cookie = `name=admin`
          document.cookie = `name=administrator`
          // document.cookie = `pwd=111111;max-age=10`
          document.cookie = `content1={'user':'a','age':10}`
          document.cookie = `content2={"user": "b","age":12}`
        }

        // sessionStorage
        document.querySelector('#sessionStorage').onclick = () => {
          sessionStorage.setItem('userId', 123456)
          sessionStorage.setItem('userId', 987654)
          sessionStorage.setItem('userInfo', '{"utserId": 121212, "username": "admin"}')
          sessionStorage.setItem('token', 'alshdhh089asdh1ge79henupdahsj9')
        }
        // localStorage
        document.querySelector('#localStorage').onclick = () => {
          localStorage.setItem('userId', 123456)
          localStorage.setItem('userId', 987654)
          localStorage.setItem('userInfo', '{"userId": 121212, "username": "admin"}')
          localStorage.setItem('token', 'alshdhh089asdh1ge79henupdahsj9')
        }

			</script>
		</body>
	</head>

</html>